package com.doctor.adapter;

import java.util.List;

import com.doctor.bean.KnowledgeBean;
import com.doctor.ui.R;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class KnowledgeUpdateAdapter extends BaseAdapter{

	/**
	 * 医学知识库升级
	 */
	
	private Context context;
	private List<KnowledgeBean> beanList;
	private int selectedIndex=-1;
	
	
	public KnowledgeUpdateAdapter(Context context, List<KnowledgeBean> beanList){
		this.context=context;
		this.beanList=beanList;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return beanList.size();
	}

	@Override
	public KnowledgeBean getItem(int arg0) {
		// TODO Auto-generated method stub
		return beanList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	public int getSelectedIndex() {
		return selectedIndex;
	}

	public void setSelectedIndex(int selectedIndex) {
		this.selectedIndex = selectedIndex;
		this.notifyDataSetChanged();
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if (arg1==null) {
			holder=new ViewHolder();
			arg1=View.inflate(context, R.layout.knowledge_update_list_item, null);
			holder.number=(TextView) arg1.findViewById(R.id.number);
			holder.name=(TextView) arg1.findViewById(R.id.name);
			holder.radio=(ImageView) arg1.findViewById(R.id.radio);
			
			arg1.setTag(holder);
		} else {
			holder=(ViewHolder) arg1.getTag();
		}
		
		KnowledgeBean bean=getItem(arg0);
		
		holder.number.setText((1+arg0)+"");
		holder.name.setText(bean.getDirname());
		
		if (arg0==selectedIndex) {
			holder.radio.setImageResource(R.drawable.checked_radio);
			arg1.setBackgroundResource(R.color.gray_green);
		} else {
			holder.radio.setImageResource(R.drawable.unchecked_radio);
			arg1.setBackgroundResource(R.color.activity_bg);
		}
		
		arg1.setTag(R.id.id_tag, bean.getId());
		return arg1;
	}

	
	
	private class ViewHolder{
		TextView number;
		TextView name;
		ImageView radio;
	}
	
	
}
